<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="common/include :: header('修改目录')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-catalog-edit" th:object="${catalog}">
			<input name="id" type="hidden" th:field="*{id}" />
			<input name="module" type="hidden"  th:field="*{module}">
			<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />

			<div class="form-group">
				<label class="col-sm-3 control-label">上级目录：</label>
				<div class="col-sm-8">
				    <div class="input-group">
						<input class="form-control" type="text" id="treeName" onclick="selectCatalogTree()" readonly="true" th:field="*{parentName}">
					    <span class="input-group-addon"><i class="fa fa-search"></i></span>
				    </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">目录名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="catalogName" th:field="*{catalogName}" id="catalogName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum" th:field="*{orderNum}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">目录状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="common/include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "content/catalog";
		var module = [[${module}]];

		$("#form-catalog-edit").validate({
			onkeyup: false,
			rules:{
				catalogName:{
					required:true
				},
				orderNum:{
					digits:true
				},
			},
		    focusCleanup: true
		});

		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-catalog-edit').serialize());
	        }
	    }

		/*目录管理-修改-选择目录树*/
		function selectCatalogTree() {
			var id = $("#treeId").val();
			if(id > 0) {
			    var options = {
					title: '目录选择',
					width: "380",
					url: prefix + "/selectCatalogTree/" + $("#treeId").val()+"-"+module,
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			} else {
        		$.modal.alertError("父目录不能选择");
        	}
		}

		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowLastLevel(tree)) {
	   			var body = layer.getChildFrame('body', index);
	   			$("#treeId").val(body.find('#treeId').val());
	   			$("#treeName").val(body.find('#treeName').val());
	   			layer.close(index);
			}
		}
	</script>
</body>
</html>
